$wgUseExternalEditor, $wgUseRCPatrol;
$fname = 'DifferenceEngine::showDiffPage';
wfProfileIn( $fname );
-
+
# If external diffs are enabled both globally and for the user,
# we'll use the application/x-external-editor interface to call
# an external diff tool like kompare, kdiff3, etc.
global $wgInputEncoding,$wgServer,$wgScript,$wgLang;
$wgOut->disable();
header ( "Content-type: application/x-external-editor; charset=".$wgInputEncoding );
- $url1=$this->mTitle->getFullURL("action=raw&oldid=".$this->mOldid);
+ $url1=$this->mTitle->getFullURL("action=raw&oldid=".$this->mOldid);
$url2=$this->mTitle->getFullURL("action=raw&oldid=".$this->mNewid);
$special=$wgLang->getNsText(NS_SPECIAL);
$control=<<<CONTROL
if ( $this->mNewRev->isCurrent() ) {
$wgOut->setArticleFlag( true );
}
-
+
$wgOut->suppressQuickbar();
$oldTitle = $this->mOldPage->getPrefixedText();
*/
function getDiffBody() {
global $wgUseExternalDiffEngine, $wgContLang, $wgMemc, $wgDBname;
-
+
// Cacheable?
$key = false;
if ( $this->mOldid && $this->mNewid ) {
return $difftext;
}
}
-
+
if ( !$this->loadText() ) {
return false;
}
-
+
$otext = $wgContLang->segmentForDiff($this->mOldtext);
$ntext = $wgContLang->segmentForDiff($this->mNewtext);
if ( $wgUseExternalDiffEngine ) {
$this->mPagetitle = htmlspecialchars( wfMsg( 'revisionasof', $t ) );
$this->mNewtitle = "<a href='$newLink'>{$this->mPagetitle}</a>";
}
-
+
$this->mNewUser = $this->mNewRev->getUserText();
$this->mNewComment = $this->mNewRev->getComment();
-
+
// Load the old revision object
$this->mOldRev = false;
if( $this->mOldid ) {
$oldLink = $this->mOldPage->escapeLocalUrl( 'oldid=' . $this->mOldid );
$this->mOldtitle = "<a href='$oldLink'>" . htmlspecialchars( wfMsg( 'revisionasof', $t ) ) . '</a>';
-
+
$this->mOldUser = $this->mOldRev->getUserText();
$this->mOldComment = $this->mOldRev->getComment();
}
-
+
return true;
}
// Whether it succeeds or fails, we don't want to try again
$this->mTextLoaded = 2;
}
-
+
if ( !$this->loadRevisionData() ) {
return false;
}
$this->mNewtext = $this->mNewRev->getText();
return true;
}
-
-
+
+
}
// A PHP diff engine for phpwiki. (Taken from phpwiki-1.3.3)
function diff ($from_lines, $to_lines) {
$fname = '_DiffEngine::diff';
wfProfileIn( $fname );
-
+
$n_from = sizeof($from_lines);
$n_to = sizeof($to_lines);
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
$xhash[$this->_line_hash($from_lines[$xi])] = 1;
}
-
+
for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
$line = $to_lines[$yi];
if ( ($this->ychanged[$yi] = empty($xhash[$this->_line_hash($line)])) )
return $line;
}
}
-
+
/* Divide the Largest Common Subsequence (LCS) of the sequences
* [XOFF, XLIM) and [YOFF, YLIM) into NCHUNKS approximately equally
else
for ($i = $ylim - 1; $i >= $yoff; $i--)
$ymatches[$this->yv[$i]][] = $i;
-
+
$this->lcs = 0;
$this->seq[0]= $yoff - 1;
$this->in_seq = array();
$ymids[0] = array();
-
+
$numer = $xlim - $xoff + $nchunks - 1;
$x = $xoff;
for ($chunk = 0; $chunk < $nchunks; $chunk++) {
if ($chunk > 0)
for ($i = 0; $i <= $this->lcs; $i++)
$ymids[$i][$chunk-1] = $this->seq[$i];
-
+
$x1 = $xoff + (int)(($numer + ($xlim-$xoff)*$chunk) / $nchunks);
for ( ; $x < $x1; $x++) {
$line = $flip ? $this->yv[$x] : $this->xv[$x];
}
wfProfileOut( "$fname-chunk" );
}
-
+
$seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
$ymid = $ymids[$this->lcs];
for ($n = 0; $n < $nchunks - 1; $n++) {
$seps[] = $flip ? array($y1, $x1) : array($x1, $y1);
}
$seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
-
+
wfProfileOut( $fname );
return array($this->lcs, $seps);
}
function _lcs_pos ($ypos) {
$fname = '_DiffEngine::_lcs_pos';
wfProfileIn( $fname );
-
+
$end = $this->lcs;
if ($end == 0 || $ypos > $this->seq[$end]) {
$this->seq[++$this->lcs] = $ypos;
else
$end = $mid;
}
-
+
USE_ASSERTS && assert($ypos != $this->seq[$end]);
-
+
$this->in_seq[$this->seq[$end]] = false;
$this->seq[$end] = $ypos;
$this->in_seq[$ypos] = 1;
function _compareseq ($xoff, $xlim, $yoff, $ylim) {
$fname = '_DiffEngine::_compareseq';
wfProfileIn( $fname );
-
+
// Slide down the bottom initial diagonal.
while ($xoff < $xlim && $yoff < $ylim
&& $this->xv[$xoff] == $this->yv[$yoff]) {
wfProfileIn( $fname );
$i = 0;
$j = 0;
-
+
USE_ASSERTS && assert('sizeof($lines) == sizeof($changed)');
$len = sizeof($lines);
$other_len = sizeof($other_changed);
-
+
while (1) {
/*
* Scan forwards to find beginning of another run of changes.
*/
while ($j < $other_len && $other_changed[$j])
$j++;
-
+
while ($i < $len && ! $changed[$i]) {
USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
$i++; $j++;
while ($j < $other_len && $other_changed[$j])
$j++;
}
-
+
if ($i == $len)
break;
-
+
$start = $i;
-
+
// Find the end of this run of changes.
while (++$i < $len && $changed[$i])
continue;
-
+
do {
/*
* Record the length of this run of changes, so that
* we can later determine whether the run has grown.
*/
$runlength = $i - $start;
-
+
/*
* Move the changed region back, so long as the
* previous unchanged line matches the last changed one.
continue;
USE_ASSERTS && assert('$j >= 0 && !$other_changed[$j]');
}
-
+
/*
* Set CORRESPONDING to the end of the changed run, at the last
* point where it corresponds to a changed run in the other file.
* CORRESPONDING == LEN means no such point has been found.
*/
$corresponding = $j < $other_len ? $i : $len;
-
+
/*
* Move the changed region forward, so long as the
* first changed line matches the following unchanged one.
$changed[$i++] = 1;
while ($i < $len && $changed[$i])
$i++;
-
+
USE_ASSERTS && assert('$j < $other_len && ! $other_changed[$j]');
$j++;
if ($j < $other_len && $other_changed[$j]) {
}
}
} while ($runlength != $i - $start);
-
+
/*
* If possible, move the fully-merged run of changes
* back to a corresponding run in the other file.
$mapped_from_lines, $mapped_to_lines) {
$fname = 'MappedDiff::MappedDiff';
wfProfileIn( $fname );
-
+
assert(sizeof($from_lines) == sizeof($mapped_from_lines));
assert(sizeof($to_lines) == sizeof($mapped_to_lines));
function WordLevelDiff ($orig_lines, $closing_lines) {
$fname = 'WordLevelDiff::WordLevelDiff';
wfProfileIn( $fname );
-
+
list ($orig_words, $orig_stripped) = $this->_split($orig_lines);
list ($closing_words, $closing_stripped) = $this->_split($closing_lines);
function _changed( $orig, $closing ) {
$fname = 'TableDiffFormatter::_changed';
wfProfileIn( $fname );
-
+
$diff = new WordLevelDiff( $orig, $closing );
$del = $diff->orig();
$add = $diff->closing();